package com.droidclaimsurveyor.dal;

import java.util.List;

import android.content.Context;

import com.droidclaimsurveyor.helper.asyntask.IProgressTracker;
import com.droidclaimsurveyor.helper.asyntask.ProgressAsynTask;
import com.droidclaimsurveyor.helper.asyntask.SpinnerTracker;


public class DatabaseLoader <T, P> extends ProgressAsynTask<P, List<T>> {
	DAL<T,P> dal;
	
	public DatabaseLoader(Context context, String progressLabel) {
		IProgressTracker tracker = new SpinnerTracker(context, progressLabel);
		setProgressTracker(tracker);
	}
	
	public void setDAL(DAL<T,P> dal){
		this.dal = dal;
	}

	@Override
	protected List<T> performTaskInBackground(P... parameters) throws Exception {
		List<T> result = null;
		
		dal.open();
		//Cursor cursor = dal.getAllCursor();
		//result = dal.mapCursor(getTaskId(), cursor, parameters);
		result = dal.getAll(getTaskId(),parameters);
		dal.close();
		
		return result;
	}

}
